package com.tanhua.appserver.controller;

import com.tanhua.appserver.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    private UserService userService;

    /**
     * 生成验证码。将验证码存入redis中
     * @param map
     * @return
     */
    @PostMapping("/login")
    public ResponseEntity login(@RequestBody Map map){
        //接受前端传过来的phone数据
        String phone = (String) map.get("phone");
        //调用userService中的login方法生成验证码
        userService.login(phone);
        System.out.println(phone);
        //返回ResponseEntity类型的ok
        return ResponseEntity.ok(null);
    }

    @PostMapping("/loginVerification")
    public ResponseEntity loginVerification(@RequestBody Map map){
        //接受前端传过来的phone数据
        String phone = (String) map.get("phone");
        //接受前端传过来的code数据
        String code = (String) map.get("verificationCode");
        Map resMap=userService.loginVerification(phone,code);
        return ResponseEntity.ok(resMap);
    }



}
